# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=phodav
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="A WebDAV server using libsoup (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsoup3"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=("${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
license=('spdx:LGPL-2.1-or-later')
url="https://wiki.gnome.org/phodav"
source=(https://download.gnome.org/sources/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.xz
        001-skip-man-for-win.patch
        002-enable-gtk-doc-for-win.patch)
sha256sums=('392ec2d06d50300dcff1ef269a2a985304e29bce3520002fca29f2edc1d138d1'
            'd5efa5820e37f305f3508baf4948ee8f0611e810a86b24489955c41afedc1595'
            'b24b7bc59c309faf6cf3c47f7e928fbb45273616b20aad49f05a785bdf0f2f68')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  # xmlto write in wrong path when pass Windows style directory from meson
  patch -p1 -i ${srcdir}/001-skip-man-for-win.patch
  patch -p1 -i ${srcdir}/002-enable-gtk-doc-for-win.patch
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --default-library=both \
    --buildtype=plain \
    -Dgtk_doc=enabled \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "${srcdir}/build-${MSYSTEM}" --destdir "${pkgdir}"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/lib${_realname}/COPYING"
}
